package com.vallis.asfc.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
import com.vallis.asfc.entity.MyResult;
import com.vallis.asfc.entity.User;
import com.vallis.asfc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vallis
 * @since 2019-12-26
 */
@RestController
@RequestMapping("/asfc/user")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @CrossOrigin
    @PostMapping(value = "login")
    public MyResult login(@RequestBody User requestUser, HttpSession session){
        System.out.print("开始执行后台交互");

        String userAsfc_sn=requestUser.getAsfcSn();
        System.out.print("接受到的会员号："+userAsfc_sn);
        User user=iUserService.getOne(new QueryWrapper<User>().ge("asfc_sn",userAsfc_sn));

        if(null==user){
            return new MyResult(400);
        }else {
            session.setAttribute("user",user);
            return new MyResult(200);
        }


    }
    @RequestMapping ("testadd")
    public MyResult testAdd(){
        User user=new User();
        user.setAsfcSn("测试会员号");
        user.setCreatTime(new Date());
        user.setCreatUser(1);
        user.setDeleteTime(new Date());
        user.setDeptId(1);
        user.setPassword("adadada");
        user.setPhoneNumber("13213465");
        user.setUserAge(10);
        user.setUserStatus(0);
        user.setUserDesc("dadasdasda");
        user.setUserGender(1);

        System.out.print("生成成功");
        if (iUserService.save(user))   {
            System.out.print("生成成功");
            return new MyResult(200);
        }else {
            System.out.print("生成成功");
            return new MyResult(400);
        }

    }
    @RequestMapping("gogogo")
    public String testboot()
    {
        return "success";
    }
}
